import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// import dataV from '@jiaminghi/data-view';
import DataVVue3 from '@kjgl77/datav-vue3'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import $ from 'jquery'
// import scroll from 'vue-seamless-scroll'

// 引入全局css
import './assets/scss/style.scss';
// 引入图表（所有图标见 icon 目录下的 demo_index.html）
import './assets/icon/iconfont.css'
import './assets/fonts/index.css'
// 引入 全局注册组件
import PublicComponent from '@/components/componentInstall';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import countUp from "@/components/countUp.vue"
import scSelect from '@/components/select/select.vue'
import scCascader from '@/components/cascader/cascader.vue'
import box from "@/components/box/box.vue";
import decorate1 from "@/components/box/decorate1.vue";
import decorate2 from "@/components/box/decorate2.vue";
import window from "@/components/box/window.vue";
import maptype from "@/components/mapContainer/mapType.vue";
import coverage from "@/components/coverage/index.vue";

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.component('countUp', countUp)
app.component('scSelect', scSelect)
app.component('scCascader', scCascader)
app.component('box', box)
app.component('decorate1', decorate1)
app.component('decorate2', decorate2)
app.component('window', window)
app.component('maptype', maptype)
app.component('coverage', coverage)
app.use(ElementPlus, {
  locale: zhCn,
})
// app.use(scroll,{componentName: 'scroll-seamless'})
app.use(PublicComponent)
// app.use(dataV)
app.use(DataVVue3)
app.use(store)
app.use(router)
app.use($)
app.mount('#app')

router.beforeEach((to, from, next) => {
  next()
  // if(process.env.NODE_ENV === 'development'){
  //   next()
  //   return
  // }
  // if(storage.state.ACCESS_TOKEN){
  //   next()
  // }else{
  //   let token = sessionStorage.getItem('access_token')
  //   if(token){
  //     storage.commit('changeACCESS_TOKEN',token)
  //     next()
  //   }
  //   else{
  //     window.location.href = Setting.entrance
  //   }
  // }
})


const getQueryData = () => {
  let oSearchItem:any = {};
  let searchString = window.location.search;
  let reg = /[?&][^?&]+=[^?&]+/g;
  let arr = searchString.match(reg);
  if (arr) {
    arr.forEach((item) => {
      let tempArr = item.substring(1).split("=");
      let key = decodeURIComponent(tempArr[0]);
      let value = decodeURIComponent(tempArr[1]);
      oSearchItem[key] = value;
    });
  }
  return oSearchItem
}

const getnewurl = ()=> {
  let url = document.location.href;
  let reg = /[^\w](token|token)=?([^&|^#]*)/g;
  url = url.replace(reg, "");
  reg = /&&/g;
  url = url.replace(reg, "");
  reg = /&#/g;
  url = url.replace(reg, "#");
  reg = /\?#/g;
  url = url.replace(reg, "#");
  reg = /\?#/g;
  url = url.replace(reg, "#");
  return url;
}